package logic

import (
	"box-ma-fresh/boxrpc/boxrpc"
	"box-ma-fresh/boxrpc/internal/svc"
	"box-ma-fresh/mysql/model"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsTypeAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsTypeAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsTypeAddLogic {
	return &GoodsTypeAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加类型
func (l *GoodsTypeAddLogic) GoodsTypeAdd(in *boxrpc.GoodsTypeAddRequest) (*boxrpc.GoodsTypeAddResponse, error) {
	// todo: add your logic here and delete this line

	goodsType := &model.GoodsType{
		TypeName: in.TypeName,
	}
	err := goodsType.GoodsTypeAdd(model.DB)
	if err != nil {
		return nil, err
	}

	return &boxrpc.GoodsTypeAddResponse{
		GoodsTypeId: int64(goodsType.ID),
	}, nil
}
